package cn.com.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import cn.com.entity.UserVo;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;

/**
 * @author liufl E-mail:Huberier@allpyra.com
 * @version 创建时间：2017年8月3日 上午11:33:43 类说明
 */
@Service
@SuppressWarnings("unchecked")
public class UserService {

	@Autowired
	RestTemplate restTemplate;

	final String SERVICE_NAME = "cloud-client-consumer";//指定提供服务的应用集群名称

	@HystrixCommand(fallbackMethod = "fallbackSearchAll")
	public List<UserVo> searchAll() {
		return restTemplate.getForObject("http://" + SERVICE_NAME + "/getAll",List.class);
	}

	@SuppressWarnings("unused")
	private List<UserVo> fallbackSearchAll() {
		System.out.println("HystrixCommand fallbackMethod handle!");
		List<UserVo> list = new ArrayList<UserVo>();
		list.add(new UserVo(999l, "错误", "RPC异常"));
		return list;
	}
}
